package API.ExceptionAPI.ThrowException;

public class Example {
    public static void main(String[] args) {
        try {
            int[] arr = {};
            System.out.println(getMax(arr));
        } catch (NullPointerException | IllegalArgumentException e) {
            System.out.println(e.getMessage());
        }
        try {
            int[] arr = null;
            System.out.println(getMax(arr));
        } catch (NullPointerException | IllegalArgumentException e) {
            System.out.println(e.getMessage());
        }
    }

    public static int getMax(int[] arr) {
        if (arr == null) {
            throw new NullPointerException("Array is null");
        } else if (arr.length == 0) {
            throw new IllegalArgumentException("Array is empty");
        }
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        return max;
    }
}
